package com.jindy.module.oaDepartTurnApply.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.jindy.module.oaEvectionApproval.controller.SyOaEvectionController;
import com.jindy.module.oaEvectionApproval.domain.SyOaEvection;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.jindy.common.annotation.Log;
import com.jindy.common.core.controller.BaseController;
import com.jindy.common.core.domain.AjaxResult;
import com.jindy.common.enums.BusinessType;
import com.jindy.module.oaDepartTurnApply.domain.SyOaDepartTurn;
import com.jindy.module.oaDepartTurnApply.service.ISyOaDepartTurnService;
import com.jindy.common.utils.poi.ExcelUtil;
import com.jindy.common.core.page.TableDataInfo;

/**
 * 离职交接申请Controller
 * 
 * @author jindy
 * @date 2023-06-26
 */
@RestController
@RequestMapping("/module/oaDepartTurnApply")
public class SyOaDepartTurnController extends BaseController
{
    private static final Logger LOGGER = LoggerFactory.getLogger(SyOaDepartTurnController.class);

    @Autowired
    private ISyOaDepartTurnService syOaDepartTurnService;

    /**
     * 查询离职交接申请列表
     */
    @PreAuthorize("@ss.hasPermi('module:oaDepartTurnApply:list')")
    @GetMapping("/list")
    public TableDataInfo list(SyOaDepartTurn syOaDepartTurn)
    {
        startPage();
        List<SyOaDepartTurn> list = syOaDepartTurnService.selectSyOaDepartTurnList(syOaDepartTurn);
        return getDataTable(list);
    }

    /**
     * 导出离职交接申请列表
     */
    @PreAuthorize("@ss.hasPermi('module:oaDepartTurnApply:export')")
    @Log(title = "离职交接申请", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SyOaDepartTurn syOaDepartTurn)
    {
        List<SyOaDepartTurn> list = syOaDepartTurnService.selectSyOaDepartTurnList(syOaDepartTurn);
        ExcelUtil<SyOaDepartTurn> util = new ExcelUtil<SyOaDepartTurn>(SyOaDepartTurn.class);
        util.exportExcel(response, list, "离职交接申请数据");
    }

    /**
     * 获取离职交接申请详细信息
     */
    @PreAuthorize("@ss.hasPermi('module:oaDepartTurnApply:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(syOaDepartTurnService.selectSyOaDepartTurnById(id));
    }

    /**
     * 新增离职交接申请
     */
    @PreAuthorize("@ss.hasPermi('module:oaDepartTurnApply:add')")
    @Log(title = "离职交接申请", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SyOaDepartTurn syOaDepartTurn)
    {
        return toAjax(syOaDepartTurnService.insertSyOaDepartTurn(syOaDepartTurn));
    }

    /**
     * 修改离职交接申请
     */
    @PreAuthorize("@ss.hasPermi('module:oaDepartTurnApply:edit')")
    @Log(title = "离职交接申请", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SyOaDepartTurn syOaDepartTurn)
    {
        return toAjax(syOaDepartTurnService.updateSyOaDepartTurn(syOaDepartTurn));
    }

    /**
     * 删除离职交接申请
     */
    @PreAuthorize("@ss.hasPermi('module:oaDepartTurnApply:remove')")
    @Log(title = "离职交接申请", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(syOaDepartTurnService.deleteSyOaDepartTurnByIds(ids));
    }

    /**
     * 提交申请
     */
    @Log(title = "离职交接审批", businessType = BusinessType.UPDATE)
    @PostMapping( "/submitApply/{id}")
    @ResponseBody
    public AjaxResult submitApply(@PathVariable Long id) {
        try {
            SyOaDepartTurn syOaDepartTurn = syOaDepartTurnService.selectSyOaDepartTurnById(id);
            syOaDepartTurnService.submitApply(syOaDepartTurn);
        } catch (Exception e) {
            LOGGER.error("离职交接审批提交申请出错",e);
            return error("离职交接审批提交申请出错：" + e.getMessage());
        }
        return success();
    }
}
